/**
 * User: alesj
 * Date: 2004.8.25
 * Time: 10:01:13
 */

package com.generalynx.ecos.utils;

import com.generalynx.common.data.ADEData;
import com.generalynx.common.constants.WebConst;

import java.util.Properties;

public class Settings {

    private Properties m_properties;

    public Settings(Properties properties) {
        m_properties = properties;
        init();
    }

    private void init() {
        WebConst.init(getProperties());
        ADEData.init(getProperties());
    }

    public Properties getProperties() {
        return m_properties;
    }
            
    public String getProperty(String key) {
        return getProperties().getProperty(key);
    }

    public String getProperty(String key, String defaultValue) {
        return getProperties().getProperty(key, defaultValue);
    }
    
    public void setProperty(String key, String property) {
        getProperties().setProperty(key, property);
    }

    public int getIntProperty(String key) {
        return Integer.parseInt(getProperty(key));
    }

    public int getIntProperty(String key, int defaultValue) {
        try {
            return getIntProperty(key);
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    }

    public double getDoubleProperty(String key) {
        return Double.parseDouble(getProperty(key));
    }

    public double getDoubleProperty(String key, double defaultValue) {
        try {
            return getDoubleProperty(key);
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    }

    public long getLongProperty(String key) {
        return Long.parseLong(getProperty(key));
    }

    public long getLongProperty(String key, long defaultValue) {
        try {
            return getLongProperty(key);
        } catch (NumberFormatException e) {
            return defaultValue;
        }
    }

    public boolean getBooleanProperty(String key) {
        return new Boolean(getProperty(key)).booleanValue();
    }
}
